/*
 * CategoryClassificationDoubleCheck is a software package that uses 
 * data mining to verify that descriptions of items are classified 
 * into the correct categories.
 * 
 * Copyright (C) 2011  CommuniPatient, LLC
 * 
 * File: Data.java
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *  
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package com.unitvectory.categoryclassification;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

/**
 * The data provided by the user.
 * 
 * @author Jared Hatfield
 * 
 */
public class Data {

	/**
	 * The list of items.
	 */
	private List<Item> items;

	/**
	 * The list of categories.
	 */
	private List<Category> categories;

	/**
	 * Initializes a new instance of the Data class.
	 */
	public Data() {
		this.items = new ArrayList<Item>();
		this.categories = new ArrayList<Category>();
	}

	/**
	 * Gets the list of items.
	 * 
	 * @return The list of items.
	 */
	public List<Item> getItems() {
		return items;
	}

	/**
	 * Gets the list of categories.
	 * 
	 * @return The list of categories.
	 */
	public List<Category> getCategories() {
		return categories;
	}

	/**
	 * Gets the suggestion for the misclassified value.
	 * 
	 * @param filename
	 *            The misclassified filename from the classifier.
	 * @param category
	 *            The category.
	 * @param confidence
	 *            The confidence.
	 * @return The item suggestion.
	 */
	public ItemSuggestion misclassifiedValue(String filename,
			Category category, double confidence) {
		File f = new File(filename);
		String id = f.getName().replace(".txt", "");
		Item item = null;
		for (int i = 0; i < this.items.size(); i++) {
			if (this.items.get(i).getId().equals(id)) {
				item = this.items.get(i);
				break;
			}
		}

		boolean add = true;
		if (item.isInCategory(category.getId())) {
			add = false;
		}

		return new ItemSuggestion(item, category, add, confidence);
	}
}
